package cn.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import cn.pojo.Score;
import cn.util.DBUtil;

public class ScoreDaoImpl extends DBUtil implements ScoreDao {

	@Override
	public Integer addScore(Score score) {
		return null;
	}

	@Override
	public List<Score> getScoreByMid(Integer mid) {
		Connection ct = getConnection();
		PreparedStatement ps = null;
		ResultSet st = null;
		String sql = "select * from score where mid = ? ;";
		try {
			ps = ct.prepareStatement(sql);
			ps.setObject(1, mid);
			st = ps.executeQuery();
			List<Score> list = new ArrayList<Score>();
			while (st.next()) {
				Score sc = new Score();
				sc.setCreateDate(st.getDate("createDate"));
				sc.setId(st.getInt("id"));
				sc.setMessage(st.getString("message"));
				sc.setMid(st.getInt("mid"));
				sc.setNum(st.getInt("num"));
				list.add(sc);
			}
			return list;
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			release(ct, ps, st);
		}
		return null;
	}
}
